<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input type="button" value="选择客户" onclick="layer_show('选择客户','/{{config('constant.name_admin')}}/client/select','','',true)">
    <div id="client_info">

    </div>
    <br>
    <div id="add_info">
        <select class="select" name="sample_type_id" size="1">
            <option value="0">请选择样品名称</option>
            @foreach($sample_type as $val)
            <option value="{{$val -> id}}">{{$val -> name}}</option>
            @endforeach
        </select>
        <select class="select" name="biaozhun_name_id" size="1">
            <option value="0">检验标准</option>
        </select>
        <select class="select" name="voltage_level" size="1" hidden>
            <option value="0">电压等级</option>
        </select>
        @foreach($sample_type as $val)
        <span id="voltage_level{{$val -> id}}" hidden>{{$val -> voltage_level}}</span>
        @endforeach
        <div id="test_items">

        </div>
    </div>
    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/admin/lib/layer/3.1.1/layer.js"></script>
    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
    <script>
        /*获取客户信息*/
        function get_client_info(id){
            $.ajax({
                type: 'GET',
                url: '/{{config('constant.name_admin')}}/client/getClientInfo?id=' + id,
                // dataType: 'json',
                success: function(data){
                    //判断添加结果 
                    if(data !== '-1'){ 
                        var html= '客户名称<input type="text" readonly value="' + data.name + '"><br> 联 系 人 <input type="text" readonly value="' +data.contact + '">';
                        $('#client_info').html(html);
                    }
                    else{
                        $('#client_info').html('');
                    }
                    
                },
                error:function(data) {
                },
                beforeSend : function () { 
                },
                complete : function () { 
                },
            });		
        }

        $(function() {
            //在选择样品类型后列出检验标准
            $('select[name=sample_type_id]').change(function(){
                //获取当前样品类型id
                var id = $(this).val();
                //在追加之前先清除之前的二级之后的数据
                $('select[name=biaozhun_name_id]').find('option:gt(0)').remove();
                $('select[name=voltage_level]').find('option:gt(0)').remove();
                $('#test_items').html('');
                if (id > 0) {
                    var str_voltage_level=$('#voltage_level' + id).html();
                    if (str_voltage_level !== '') {
                        var arr = str_voltage_level.split(',');
                        //jQuery的循环操作
                        var str_v = '';
                        $.each(arr,function(index,el){
                            str_v += "<option value='" + el + "'>" + el + "</option>";
                        });
                        //将数据放到对应的option之后
                        $('select[name=voltage_level]').show().append(str_v);
                    }else{
                        $('select[name=voltage_level]').hide();
                    }

                    $.get('/{{config('constant.name_admin')}}/contract/getSonName',{id: id},function(data){
                        //jQuery的循环操作
                        var str = '';
                        $.each(data,function(index,el){
                            str += "<option value='" + el.id + "'>" + el.name + "</option>";
                        });
                        //将数据放到对应的option之后
                        $('select[name=biaozhun_name_id]').append(str);
                    },'json');
                }else{
                    $('select[name=voltage_level]').hide();
                }
            });

            /* 在选择检验标准后列出检测项目 */
            $('select[name=biaozhun_name_id]').change(function(){
                //获取当前检验标准id
                var id = $(this).val();
                //在追加之前先清除之前的二级之后的数据
                $('#test_items').html('');
                if (id > 0) {
                    $.get('/{{config('constant.name_admin')}}/contract/getSonName',{id: id},function(data){
                        //jQuery的循环操作
                        var str = '';
                        $.each(data,function(index,el){
                            str += "<label><input type='checkbox' value='" + el.id + "'>" + el.name + "</label>";
                        });
                        //将数据放到对应的option之后
                        $('#test_items').html(str);
                    },'json');
                }
            });
        });
    </script>
</body>

</html>